<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('住户信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 住户资料
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
         `<div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="parentId" name="parentId" value="1">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>地址名称：</label>
                                    <input type="text" name="locationName"/>
                                </li>
                                <li>
                                    <label>地址类型：</label>
                                    <select name="locationType" th:with="type=${@dict.getType('location_type')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>供暖状态：</label>
                                    <select id="status" name="status">
                                        <option value="">所有</option>
                                        <option value="1">缴费</option>
                                        <option value="0">未缴费</option>
                                    </select>
                                </li>
                                <li>
                                    <label>报警状态：</label>
                                    <select id="alarmStatus" name="alarmStatus">
                                        <option value="">所有</option>
                                        <option value="1">启用</option>
                                        <option value="0">未启用</option>
                                    </select>
                                </li>
                                <li>
                                    <label>用户姓名：</label>
                                    <input type="text" name="locationHode"/>
                                </li>
                                <li>
                                    <label>用户号：</label>
                                    <input type="text" name="locationNumber"/>
                                </li>
                                <li>
                                    <label>联系方式：</label>
                                    <input type="text" name="locationContact"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="base:location:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="base:location:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-warning" onclick="$.table.importExcel()" shiro:hasPermission="base:location:import">
                        <i class="fa fa-upload"></i> 导入
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="base:location:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>`
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('base:location:add')}]];
        var editFlag = [[${@permission.hasPermi('base:location:edit')}]];
        var removeFlag = [[${@permission.hasPermi('base:location:remove')}]];
        var prefix = ctx + "base/location";

        var datas = [[${@dict.getType('location_type')}]];

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryInfoList();
            queryLocationTree();
        });

        function queryInfoList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "住户信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'locationId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'locationName',
                    title: '地址名称'
                },
                {
                    field: 'locationType',
                    title: '地址类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'parentName',
                    title: '上级地址名称'
                },
                {
                    field: 'locationHode',
                    title: '用户姓名'
                },
                {
                    field: 'locationContact',
                    title: '联系方式'
                },
                {
                    field: 'locationNumber',
                    title: '用户号'
                },
                {
                    field: 'collectorCount',
                    title: '采集器数量',
                    formatter: function(value, row, index) {
                        if(value > 0){
                            return '<a href="javascript:void(0)" onclick="collector(\'' + row.locationId + '\')">' + value + '</a>';
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'meterCount',
                    title: '热表数量',
                    formatter: function(value, row, index) {
                        if(value > 0){
                            return '<a href="javascript:void(0)" onclick="meter(\'' + row.locationId + '\')">' + value + '</a>';
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'valveCount',
                    title: '阀门数量',
                    formatter: function(value, row, index) {
                        if(value > 0){
                            return '<a href="javascript:void(0)" onclick="valve(\'' + row.locationId + '\')">' + value + '</a>';
                        }else{
                            return value;
                        }

                    }
                },
                {
                    field: 'tempCount',
                    title: '温度采集器数量',
                    formatter: function(value, row, index) {
                        if(value > 0){
                            return '<a href="javascript:void(0)" onclick="temp(\'' + row.locationId + '\')">' + value + '</a>';
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'deptName',
                    title: '所属部门'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '供暖状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return locationUser(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '报警状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return locationAlarm(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.locationId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.locationId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function queryLocationTree()
        {
            var url = ctx + "base/location/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#parentId").val(treeNode.id);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryLocationTree();
        });

        /* 采集器新增 */
        function add() {
            var parentId = $("#parentId").val();
            if(parentId==''){
                parentId = 1;
            }
            var url = prefix + '/add/' + parentId;
            $.modal.open("新增住户", url);
        }

        /*设备列表-详细*/
        function collector(locationId) {
            var url = ctx + 'base/collector/info/location/' + locationId;
            $.modal.openTab("采集器设备", url);
        }

        /*设备列表-详细*/
        function meter(locationId) {
            var url = ctx + 'data/meter/location/' + locationId;
            $.modal.openTab("热表采集数据", url);
        }

        /*设备列表-详细*/
        function valve(locationId) {
            var url = ctx + 'data/valve/location/' + locationId;
            $.modal.openTab("阀门采集数据", url);
        }

        /*设备列表-详细*/
        function temp(locationId) {
            var url = ctx + 'data/temp/location/' + locationId;
            $.modal.openTab("温度采集数据", url);
        }


        /* 用户状态显示 */
        function locationUser(row) {
            if (row.status == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.locationId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.locationId + '\')"></i> ';
            }
        }
        /* 用户管理-停用 */
        function disable(locationId) {
            $.modal.confirm("确认要停用用户吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "locationId": locationId, "status": 0 });
            })
        }

        /* 用户管理启用 */
        function enable(locationId) {
            $.modal.confirm("确认要启用用户吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "locationId": locationId, "status": 1 });
            })
        }

        /* 用户状态显示 */
        function locationAlarm(row) {
            if (row.alarmStatus == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enablea(\'' + row.locationId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disablea(\'' + row.locationId + '\')"></i> ';
            }
        }
        /* 用户管理-停用 */
        function disablea(locationId) {
            $.modal.confirm("确认要停用用户报警吗？", function() {
                $.operate.post(prefix + "/changeAlarmStatus", { "locationId": locationId, "alarmStatus": 0 });
            })
        }

        /* 用户管理启用 */
        function enablea(locationId) {
            $.modal.confirm("确认要启用用户报警吗？", function() {
                $.operate.post(prefix + "/changeAlarmStatus", { "locationId": locationId, "alarmStatus": 1 });
            })
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果信息已经存在，更新这条数据。"> 是否更新已经存在的信息
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>